import { User as UserInterface } from '@prisma/client';
import { objectType } from "nexus";
import { User } from "nexus-prisma";

// Define a User Entity
export const UserEntity = objectType({
    name: User.$name,
    description: User.$description,
    definition(t) {
        t.field(User.id);
        t.field(User.username);
        t.field(User.createdAt);
        t.field(User.profile);
        t.field({
            ...User.security,
            // @ts-ignore
            authorize(user: UserInterface, _args: any, context: RuntimeContext) {
                console.log(user);
                return context.user?.id === user.id;
            },
        });
    },
});
